package itman.elm.controller;

import itman.elm.po.DeliveryAddress;
import itman.elm.service.DeliveryAddressService;
import itman.elm.service.impl.DeliveryAddressServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("DeliveryAddressController")
public class DeliveryAddressController {

    @Autowired
    private DeliveryAddressService deliveryAddressService;

    /**
     * 根据用户编号查询所属送货地址
     * @param userId
     * @return
     */
    @RequestMapping("listDeliveryAddressByUserId")
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId){
        return deliveryAddressService.listDeliveryAddressByUserId(userId);
    }

    /**
     *根据送货地址编号查询送货地址
     * @param daId
     * @return
     */
    @RequestMapping("getDeliveryAddressById")
    public DeliveryAddress getDeliveryAddressById(Integer daId){
        return deliveryAddressService.getDeliveryAddress(daId);
    }

    /**
     * 向送货地址表中添加一条记录
     * @param deliveryAddress
     * @return
     */
    @RequestMapping("saveDeliveryAddress")
    public int saveDeliveryAddress(DeliveryAddress deliveryAddress){
        return deliveryAddressService.saveDeliveryAddress(deliveryAddress);
    }

    /**
     * 根据送货地址编号更新送货地址信息
     * @param deliveryAddress
     * @return
     */
    @RequestMapping("updateDeliveryAddress")
    public int updateDeliveryAddress(DeliveryAddress deliveryAddress){
        return deliveryAddressService.updateDeliveryAddress(deliveryAddress);
    }

    /**
     * 根据送货地址编号删除一条记录
     * @param daId
     * @return
     */
    @RequestMapping("removeDeliveryAddress")
    public int removeDeliveryAddress(Integer daId){
        return deliveryAddressService.removeDeliveryAddress(daId);
    }
}
